﻿
<div>
    <div id="searchControls">
        @{Html.RenderPartial("SearchControls");}
    </div>

    <div id="searchResults">
        @{
            Html.RenderPartial("Search");
        }
    </div>
</div>    

<script type="text/javascript">

    $(document).ready(function () {
        $("input[id='cmdSearch']").click(Search);
        $("input[id='txtSearch']").keypress(SearchOnReturn);
        $("input[id='cmdDelete']").click(DeleteHandler);

    });

    var SearchOnReturn = function (eventArgs) {
        if (eventArgs.which == '13') 
            Search();
    };

    var Search = function () {
        var searchText = $("input[id='txtSearch']").val();

        $.ajax({ type: "POST",
            url: "/Home/Search",
            data: "SearchFilter=" + searchText,
            success: function (viewHtml) {
                $("#searchResults").html(viewHtml);
            }
        });
    };

    var DeleteHandler = function () {
        var id = $(this).parent().parent().children("td:eq(0)").text();
        alert(id);
        $.ajax({ type: "POST",
            url: "/Home/Delete",
            data: "CustomerID=" + id,
            success: function (viewhtml) {
                window.location.href = "http://" + window.location.host;
            }
        });

    };

</script>
